﻿<!--Copyright (c) 2009 T.Evelyn (evescode@gmail.com) 

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1.Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2.Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in 
 the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 

THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 

BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 

GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 

LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 

DAMAGE.-->
    
    <ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MvcXamlController.Controls">
    <!-- Type converters-->
    <local:ImageOffsetConverter x:Key="imageOffsetConverter" />
    <local:RadiusToDiameterConverter x:Key="radiusToDiameterConverter"/>
    <local:PointerCenterConverter x:Key="pointerCenterConverter"/>
    <local:RangeIndicatorLightPositionConverter x:Key="rangeIndicatorLightPositionConverter"/>
    <local:SizeConverter x:Key="sizeConverter" />
    <local:BackgroundColorConverter x:Key="backgroundColorConverter" />
    <local:GlassEffectWidthConverter x:Key="glassEffectWidthConverter" />
    <local:ColorToSolidColorBrushConverter x:Key="colorToSolidColorBrushConverter" />


    <Style TargetType="local:CircularGaugeControl" >
        <Setter Property="ResetPointerOnStartUp" Value="True" />
        <Setter Property="ScaleValuePrecision" Value="5" />
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AFD6" Offset="0.321"/>
                    <GradientStop Color="#FF8399A9" Offset="0.674"/>
                    <GradientStop Color="#FF718597" Offset="0.375"/>
                    <GradientStop Color="#FF617584" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="RangeIndicatorThickness" Value="5"/>
        <Setter Property="GaugeBackgroundColor" Value="Black" />
        <Setter Property="BelowOptimalRangeColor" Value="Yellow" />
        <Setter Property="OptimalRangeColor" Value="Green" />
        <Setter Property="AboveOptimalRangeColor" Value="Red" />
        <Setter Property="DialTextColor" Value="White" />
        <Setter Property="DialTextFontSize" Value="8" />

        <Setter Property="Template" >
            <Setter.Value>
                <ControlTemplate TargetType="local:CircularGaugeControl">
                    <!-- Root Grid-->
                    <Grid x:Name="LayoutRoot" 
                          Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Radius, Converter={StaticResource radiusToDiameterConverter}}" 
                          Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Radius, Converter={StaticResource radiusToDiameterConverter}}" >


                        <Ellipse x:Name="OuterFrame" StrokeThickness="16" 
                                 Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Radius, Converter={StaticResource radiusToDiameterConverter}}" 
                                 Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Radius, Converter={StaticResource radiusToDiameterConverter}}" 
                                 Fill="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=GaugeBackgroundColor, Converter={StaticResource backgroundColorConverter}}">

                            <Ellipse.Stroke>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF636060" Offset="1"/>
                                    <GradientStop Color="#FF5F5C5C" Offset="0"/>
                                    <GradientStop Color="#FFEEDEDE" Offset="0.35"/>
                                    <GradientStop Color="#FFA09595" Offset="0.705"/>
                                </LinearGradientBrush>
                            </Ellipse.Stroke>
                        </Ellipse>


                        <!-- Gauge Image -->
                        <Image Source="{TemplateBinding ImageSource}" 
                               Width="{Binding RelativeSource={RelativeSource TemplatedParent}, 
                            Path=ImageSize, Converter={StaticResource sizeConverter}, ConverterParameter=Width }" 
                               
                               Height="{Binding RelativeSource={RelativeSource TemplatedParent}, 
                            Path=ImageSize, Converter={StaticResource sizeConverter}, ConverterParameter=Height }"
                               
                               RenderTransform="{Binding RelativeSource={RelativeSource TemplatedParent}, 
                            Path=ImageOffset, Converter={StaticResource imageOffsetConverter}}">

                        </Image>

                        <!-- Dial Text -->
                        <TextBlock Text="{TemplateBinding DialText}"  
                                   HorizontalAlignment="Center" VerticalAlignment="Center"  
                                   Foreground="{Binding RelativeSource={RelativeSource TemplatedParent}, 
                            Path=DialTextColor, Converter={StaticResource colorToSolidColorBrushConverter}}"
                                   FontSize="{TemplateBinding DialTextFontSize}"                             
                                   FontWeight="Bold"
                                                         
                              RenderTransform="{Binding RelativeSource={RelativeSource TemplatedParent}, 
                            Path=DialTextOffset, Converter={StaticResource rangeIndicatorLightPositionConverter}}">

                        </TextBlock>

                        <!-- Pointer -->
                        <Path x:Name="Pointer" Stroke="#FFE91C1C" StrokeThickness="2" 
                              Width="{TemplateBinding PointerLength}" 
                              Height="{TemplateBinding PointerThickness}" HorizontalAlignment="Center"
                              Data="M1,1 L1,10 L156,6 z" Stretch="Fill"  RenderTransformOrigin="0,0.5" 
                              RenderTransform="{Binding RelativeSource={RelativeSource TemplatedParent}, 
                            Path=PointerLength, Converter={StaticResource pointerCenterConverter}}">
                            <Path.Fill>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF890A0A" Offset="0.197"/>
                                    <GradientStop Color="#FFC40808" Offset="1"/>
                                    <GradientStop Color="#FFE32323" Offset="0.61"/>
                                </LinearGradientBrush>
                            </Path.Fill>

                        </Path>


                        <!--Pointer Cap-->
                        <Ellipse x:Name="PointerCap" Height="{TemplateBinding PointerCapRadius}" Width="{TemplateBinding PointerCapRadius}" StrokeThickness="4" Opacity="1" >
                            <Ellipse.Stroke>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF000000" Offset="0.675"/>
                                    <GradientStop Color="#FFC1B5B5" Offset="0.031"/>
                                </LinearGradientBrush>
                            </Ellipse.Stroke>
                            <Ellipse.Fill>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF152029" Offset="0.846"/>
                                    <GradientStop Color="#FF140204" Offset="0.342"/>
                                </LinearGradientBrush>
                            </Ellipse.Fill>
                        </Ellipse>

                        <!--Range indicator light-->
                        <Ellipse x:Name="RangeIndicatorLight" 
                                  Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RangeIndicatorLightRadius, Converter={StaticResource radiusToDiameterConverter}}" 
                                  Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=RangeIndicatorLightRadius, Converter={StaticResource radiusToDiameterConverter}}" 
                                
                                RenderTransform="{Binding RelativeSource={RelativeSource TemplatedParent}, 
                                Path=RangeIndicatorLightOffset, Converter={StaticResource rangeIndicatorLightPositionConverter}}">
                            <!--Range indicator light off position effect-->
                            <Ellipse.Fill>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                    <GradientStop Color="LightGray" Offset="0.2" />
                                    <GradientStop Color="Gray" Offset="0.5" />
                                    <GradientStop Color="Black" Offset="0.8" />
                                </LinearGradientBrush>
                            </Ellipse.Fill>
                        </Ellipse>

                        <!--Glass effect ellipse-->
                        <Path x:Name="GlassEffect" StrokeThickness="1" Stretch="Fill" VerticalAlignment="Bottom"
                              Height="{TemplateBinding Radius}"
                              Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Radius, Converter={StaticResource glassEffectWidthConverter}}" 
                              Opacity="0.18" Data="M265.99997,151.00005 C263.99994,194.00003 209.55908,259 135.00064,259 C60.442207,259 11,200.00003 5.9999995,157.00005 C5.0181994,148.55656 73.000877,112.00006 137.00053,112.00007 C199.00887,112.00008 266.72015,135.5164 265.99997,151.00005 z">
                            <Path.Fill>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#68FCFCFC"/>
                                    <GradientStop Color="#FFF8FCF8" Offset="1"/>
                                </LinearGradientBrush>
                            </Path.Fill>
                        </Path>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
